GtkMenuTracker: rework action removal a bit
authorRyan Lortie <desrt@desrt.ca>
Sat, 4 Jan 2014 07:11:24 +0000 (02:11 -0500)
committerRyan Lortie <desrt@desrt.ca>
Wed, 8 Jan 2014 19:21:18 +0000 (14:21 -0500)
Refactor the code in the action observer remove function in order to
make way for the (efficient) handling of hiding of the item in the case
that hidden-when='' is given.

https://bugzilla.gnome.org/show_bug.cgi?id=688421

gtk/gtkmenutrackeritem.c

index dc46be891db7a136e27ea5489caca3bd524c0353..d81c9de8e517cb43345e944456c2188f7737d5a1 100644 (file)
@@ -353,31 +353,31 @@ gtk_menu_tracker_item_action_removed (GtkActionObserver   *observer,
                                       const gchar         *action_name)
 {
   GtkMenuTrackerItem *self = GTK_MENU_TRACKER_ITEM (observer);
+  gboolean was_sensitive, was_toggled;
+  GtkMenuTrackerItemRole old_role;
 
   if (!self->can_activate)
     return;
 
+  was_sensitive = self->sensitive;
+  was_toggled = self->toggled;
+  old_role = self->role;
+
   self->can_activate = FALSE;
+  self->sensitive = FALSE;
+  self->toggled = FALSE;
+  self->role = GTK_MENU_TRACKER_ITEM_ROLE_NORMAL;
 
   g_object_freeze_notify (G_OBJECT (self));
 
-  if (self->sensitive)
-    {
-      self->sensitive = FALSE;
-      g_object_notify_by_pspec (G_OBJECT (self), gtk_menu_tracker_item_pspecs[PROP_SENSITIVE]);
-    }
+  if (was_sensitive)
+    g_object_notify_by_pspec (G_OBJECT (self), gtk_menu_tracker_item_pspecs[PROP_SENSITIVE]);
 
-  if (self->toggled)
-    {
-      self->toggled = FALSE;
-      g_object_notify_by_pspec (G_OBJECT (self), gtk_menu_tracker_item_pspecs[PROP_TOGGLED]);
-    }
+  if (was_toggled)
+    g_object_notify_by_pspec (G_OBJECT (self), gtk_menu_tracker_item_pspecs[PROP_TOGGLED]);
 
-  if (self->role != GTK_MENU_TRACKER_ITEM_ROLE_NORMAL)
-    {
-      self->role = GTK_MENU_TRACKER_ITEM_ROLE_NORMAL;
-      g_object_notify_by_pspec (G_OBJECT (self), gtk_menu_tracker_item_pspecs[PROP_ROLE]);
-    }
+  if (old_role != GTK_MENU_TRACKER_ITEM_ROLE_NORMAL)
+    g_object_notify_by_pspec (G_OBJECT (self), gtk_menu_tracker_item_pspecs[PROP_ROLE]);
 
   g_object_thaw_notify (G_OBJECT (self));
 }